<?php
/**
 * IWpConnect.php
 * 
 * This file contains the interface for WpConnect classes
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage dataaccess.wpconnect
 */ 


/**
 * The interface for WpConnect implementations
 * 
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage dataaccess.wpconnect
 */
interface IWpConnect
{
	/**
	 * The class constructor
	 * @param object $config[optional] The configuration object
	 * @cfg string location The location of the datasource to use
	 * @cfg string user	The user to use for datasource authentication
	 * @cfg string password The password to use for authentication
	 * @cfg object log A log object to log errors to (must implement the interface IWPLog).
	 * If no log object given, the errors are logged to an array which can be retrieved by getLog
	 */
	function __construct($config = null);
	
	/**
	 * Counts the requests collected for a multi-request
	 * @return The number of request in the current multi request
	 */
	function countMultiRequests();
	
	/** 
	 * Permanently deletes data from a table
	 * @param string $table The table to delete data of.
	 * @param string $condition The condition to use for matching the data to remove
	 * @return bool True if successfully deleted, false else
	 */
	function delete($table, $condition);

	/**
	 * Executes a sql statement. 
	 * @param string $statement The statement to execute
	 * @return mixed True if successfully executed, false else
	 */
	function exec($statement);
	
	/** 
	 * Retrieves the id of the last inserted dataset (for auto-increment only). This method 
	 * may not be supported by all WpConnect implementations
	 * @return var The id of the last inserted dataset
	 */
	function getInsertId();
	
	/**
	 * Retrieves the result of the last query or command
	 * @param string $type The type of the return value (objects, arrays, assocs, custom)
	 * @param object $custom An object which is used to retrieve the data customized
	 * @return mixed Returns the converted result
	 */
	function getResult($type='objects', &$custom=null);
	
	/** 
	 * Retrieves the total number of datasets (not the number, limited by LIMIT)
	 * @return int The number of datasets returned or affected by a query
	 */
	function getTotal();
	
	/** 
	 * Insert data to a table
	 * @param string $table The table to insert data to.
	 * @param array $insertion An associative array containing key/value pairs of the data to insert
	 * @return bool True if successfully done, else false
	 */
	function insert($table, $insertion);
	
	/**
	 * Determines wether a multirequest was started or not
	 * @return True if multirequest was started, false else
	 * @see startMultiRequest()
	 * @see stopMultiRequest()
	 */
	function isMultiRequest();
	
	/**
	 * Starts processing all requests collected before for a multi request
	 * @return The number of requests processed or false on error
	 * @see startMultiRequest()
	 * @see stopMultiRequest()
	 */
	function processMultiRequest();
	
	/**
	 * Reset the connector for a new query
	 */
	function reset();
	
	/** 
	 * Selects data from a table by using a condition to match
	 * @param string $fields The fields to retrieve from table as comma separated string or * for all fields
	 * @param string $table The table to select data from.
	 * @param string $condition The condition to use for data selection
	 * @param string $sort[optional] The column(s) to sort the data by (default "")
	 * @param string $dir[optional] The sort direction (ASC or DESC) (default "ASC")
	 * @param int $limit[optional] The number of datasets to return
	 * @param int $start[optional] The start dataset of the datasets to return
	 * @return bool True if successfully done, false else
	 */
	function select($fields, $table, $condition, $sort='', $dir='ASC', $limit=0, $start=0);
	
	/**
	 * Starts a multi request to collect requests and fire only one transaction
	 * @param bool $insert[optional] True, to collect insert requests for transaction, false else
	 * @param bool $update[optional] True, to collect update requests for transaction, false else
	 * @param bool $delete[optional] True, to collect delete requests for transaction, false else
	 */
	function startMultiRequest($insert=true, $update=true, $delete=true);
	
	/**
	 * Stops collecting requests for multi request, and optionally starts the mutli request
	 * @return The number of requests processed
	 * @param bool $process[optional] True, to start processing the multi request, false else
	 */
	function stopMultiRequest($process=false);
	
	/** 
	 * Updates data of a table
	 * @param string $table The table to update data of.
	 * @param array $insertion An associative array containing key/value pairs of the data to update
	 * If a field is missing, its value will not be updated but kept in table
	 * @param string $condition The condition to use to find the data to update
	 * @return bool True if succesfully updated, false else
	 */
	function update($table, $update, $condition, $limit=0, $start=0, $sort='', $dir='ASC');
}

/* End of file IWpConnect.php */
/* Location: ./wildpack/dataaccess/wpconnect/IWpConnect.php */ 
